package cn.edu.zafu.bigdata.cccnnn.worktwo;


import javax.swing.*;
import java.util.LinkedList;
import java.util.List;

class findmax {

    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            throw new IllegalArgumentException("List must not be null or empty");
        }
        T max = list.get(0);
        for (T element : list) {
            if (element.compareTo(max) > 0) {
                max = element;
            }
        }
        return max;
    }
}

public class Testfindmax {
    public static void main(String[] args){
        List <Integer> listInteger = new LinkedList<Integer>();
        List <String> listString = new LinkedList<String>();


        listInteger.add(2);
        listInteger.add(4);
        listInteger.add(7);
        listInteger.add(5);
        listInteger.add(3);

        Integer maxInt=findmax.findMax(listInteger);
        System.out.println("最大的整数为："+maxInt);


        listString.add("a");
        listString.add("f");
        listString.add("v");
        listString.add("w");
        listString.add("p");
        String maxString=findmax.findMax(listString);
        System.out.println("最大的字符串为："+maxString);

    }
}